package ciyuan.Tasks;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;

import java.util.Vector;

/**
 * @author 150149
 */
@Mod.EventBusSubscriber
public class PlayerTaskManager {

    public interface PlayerTask {
        void run(PlayerEntity playerEntity);
    }

    private static final Vector<PlayerTask> playerTaskList = new Vector<>();

    public static void register(PlayerTask playerTask) {
        playerTaskList.add(playerTask);
    }

    @SubscribeEvent
    public static void onServerStarting(FMLServerStartingEvent event) {
        playerTaskList.forEach(task -> {
            TaskManager.addTask(() -> {
                event.getServer().getPlayerList().getPlayers().forEach(task::run);
            });
        });
    }

}
